package leetcode.Greedy;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.PriorityQueue;

public class Lc2406 {


    public int minGroups(int[][] intervals) {
        Arrays.sort(intervals, (a, b) -> a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]);
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        for (int[] x : intervals) {
            if (!pq.isEmpty() && pq.peek() < x[0])
                pq.poll();
            pq.offer(x[1]);
        }
        return pq.size();
    }
}
